<template lang="pug">
    skin(@back="back",    @during-yes="exhaust",    @yes-end="stop",    @yes-moved="stop",    :yes-long-tab="true")
        div(class="flex-column charge-exhaust-exhaust")
            div(class="flex-column-item center flex-center-center flex-2",v-if="!exhausting")
                span 确认管路脱离人体
            div(class="flex-column-item flex-center-center")
                span(v-if="!exhausting") 按住ACT开始排气
                span(v-else, class="iconfont",style="font-size:200%") &#xe93a;
            div(class="flex-column-item flex-center-center")
                div(v-if="!exhausting") 按ESC返回
                span(v-else) 排气中: {{remaining}}U
</template>

<script>
    export default {
        data() {
            return {
                activeId: 0,
                page: {maxResultCount: 3, skipCount: 0},
                visible: false,
                amount: 19.6,
                exhausting: false, // 复位完成
                timeout: null,
                exhaustPause: null,
                interval: null,
                remaining: 0, // 剩余的排气量
                exhaustAmount: 0, // 排气总量

            };
        },
        methods: {
            back() {
                clearInterval(this.interval);
                if (this.exhaustAmount > 0) {
                    // 退出要写入记录
                    window.excharge.exhaustRecords.push({date: new Date, amount: this.exhaustAmount});
                    this.exhaustAmount = 0;
                }
                this.$router.push("index?index=1");
            },
            exhaust(){
                this.exhausting = true;
                let afterReduce = (window.excharge.exhaustTotal * 10 - 1.2 * 10) / 10; // 减去1.2后的剩余可以排气的量
                if (afterReduce > 0) {
                    window.excharge.exhaustTotal = afterReduce;
                    this.exhaustAmount = (this.exhaustAmount * 10 + 1.2 * 10) / 10; // 已经排气的量加到以排气的总量总
                    window.dose.remainingAmount = (window.dose.remainingAmount * 10 + 1.2 * 10) / 10; // 需要加到全局的总共剩下多少胰岛素上
                } else {
                    window.dose.remainingAmount = (window.dose.remainingAmount * 10 + window.excharge.exhaustTotal * 10) / 10; // 需要加到全局的总共剩下多少胰岛素上

                    this.exhaustAmount = (this.exhaustAmount * 10 + window.excharge.exhaustTotal * 10) / 10; // 剩余的量加入到总量中
                    window.excharge.exhaustTotal = 0;
                    if (this.exhaustAmount > 0) {
                        window.excharge.exhaustRecords.push({date: new Date, amount: this.exhaustAmount});
                        this.exhaustAmount = 0;
                    }
                }
                this.remaining = window.excharge.exhaustTotal;
            },
            stop(){
                this.exhausting = false;
            }
        }
    };
</script>
